package ren.nearby.http.permission;


import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;

import ren.nearby.http.R;
import ren.nearby.http.adapter.listener.OnItemClickListener;

/**
 * 权限 dialog
 * Created by Administrator on 2018/5/31 0031.
 */

public class PermissionDialogFragment extends DialogFragment {
    private String contract_no;

    public static PermissionDialogFragment newInstance(ArrayList<PermissionBean> selectors) {
        PermissionDialogFragment fragment  = new PermissionDialogFragment();
        Bundle args = new Bundle();
        args.putParcelableArrayList("bean", selectors);
        fragment.setArguments(args);
        return fragment ;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        /**
         * setStyle() 的第一个参数有四个可选值：
         * STYLE_NORMAL|STYLE_NO_TITLE|STYLE_NO_FRAME|STYLE_NO_INPUT
         * 其中 STYLE_NO_TITLE 和 STYLE_NO_FRAME 可以关闭标题栏
         * 每一个参数的详细用途可以直接看 Android 源码的说明
         */
        setStyle(PermissionDialogFragment.STYLE_NO_TITLE, R.style.permission_dialog_style);
        list = getArguments().getParcelableArrayList("bean");

    }

    OnCancelClick onCancelClick;

    public interface OnCancelClick {

        void cancel();

        void dialPhone();


    }

    public void setOnCancelClick(OnCancelClick onCancelClick) {
        this.onCancelClick = onCancelClick;
    }

    PermissionAdapter financesPopAdapter;
    ArrayList<PermissionBean> list;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.permission_dialog, container, false);

        RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.permission_recycler_view);
        financesPopAdapter = new PermissionAdapter(list);
        financesPopAdapter.setActivity(getActivity());
        financesPopAdapter.setOnItemClickListener(new OnItemClickListener<PermissionBean>() {

            @Override
            public void onClick(View view, PermissionBean item) {
//                onCancelClick.clickItem(item.getId(), item.getType_name());
//                financesPopAdapter.notifyItem(item.getType_name(), true);

            }
        });

        recyclerView.setHasFixedSize(true);//固定大小
        GridLayoutManager mgr = new GridLayoutManager(getActivity(), 3);
        recyclerView.setLayoutManager(mgr);
        recyclerView.setAdapter(financesPopAdapter);

        view.findViewById(R.id.permission_dialog_cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onCancelClick.cancel();
            }
        });
        view.findViewById(R.id.permission_dialog_submit).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onCancelClick.dialPhone();
            }
        });
        return view;
    }
}
